
///
/// This is the Server class
///

#ifndef SERVER_H
#define SERVER_H

#include "common.h"
#include "Handler.h"
#include <map>

#define BACKLOG 10

typedef std::map<int, Handler> HandlerMapType;

class Server
{

public:


	int Initialize(const char* ip, const char* portNo);

	// we'll see about other constructors

	int Execute();

	static Server* GetInstance() { if(mServer == NULL) mServer = new Server; return mServer; }

	static void Destroy() { if(mServer) delete mServer; }

/*	// Here are the handlers
	int HandleJoinCommand(int sockFD, std::string& userName);
	int HandleLeaveCommand(int sockFD);
	int HandleSendCommand(int sockFD, const std::string& message);
*/
private:

	// private constructor for singleton
	Server() {}

/*	void UpdateMaxFd();
	int SendOnlineToOthers(int sockFD);
	int SendAck(int sockFD);
	int SendNak(int sockFD, NAK_TYPE nakType);
	void KillClient(int sockFD);

*/	
	int mMainFD;
	fd_set mConnectedFDS;
	int mMaxFD;
	
	char mMsgBuf[MSG_BUF_SIZE];

	HandlerMapType mClientMap;

	static Server* mServer;

};

#endif //SERVER_H
